package top.codedance.iotp.client.plugins.async.mqtt;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.client.ClientApplication;
import top.codedance.iotp.common.executer.AsyncAbstractExecuter;
import top.codedance.iotp.common.constent.Command;
import top.codedance.iotp.common.entity.CommonEntity;

public abstract class Service {
    protected AsyncAbstractExecuter executer;
    protected MqttServerParam param;

    public Service(AsyncAbstractExecuter executer, MqttServerParam param){
        this.executer = executer;
        this.param = param;
    }

    /**
     * 发送信息给所有监听本主题的客户端
     * @param topic
     * @param body
     */
    public abstract void receipt(String topic, JSONObject body);

    /**
     * 写入mqtt数据
     * @param topic
     * @param message
     */
    public abstract void send(String topic, JSONObject message);



    /**
     * 统一获取发送实体
     * @return
     */
    protected CommonEntity genCommonEntity(){
        CommonEntity ce = new CommonEntity();
        ce.setCommand(Command.ASYNC_MQTT_COMMAND_RECEIVE);
        ce.setVersion(ClientApplication.getDataVersion());
        return ce;
    }
}
